/**
 * Created by zhangwenlei on 2017/5/9.
 */
ADF.domControl.ButtonGroup = function(parent) {
        ADF.domControl.ButtonGroup.superclass.constructor.call(this, parent);
        this.feedbackDom=null;
    };

    COM.util.defineClass(ADF.domControl.ButtonGroup, ADF.domControl.Composite, {
        getLabel: function(){
            return "ButtonGroup";
        },
        appendDomChild: function(child) {
            this.getDomElement().children[0].appendChild(child);
        },
        removeDomChild: function(child) {
            this.getDomElement().children[0].removeChild(child);
        },
        _getDomElement: function(model) {
            var buttongroup=this.createButtonGroup( );
            var buttongroupWrap=this.createButtongroupWrap(model);
            buttongroupWrap.append(buttongroup);
            this.domElement = buttongroupWrap[0];
            return this.domElement;
        },
        createButtonGroup:function ( ) {
            var buttongroup = COM.util.HTMLUtil.createELement('<div class="btn-group" role="group"></div>');
            var css={"position":"relative","overflow":"visible","width":"100%"};
            css.minHeight=10;
            buttongroup.css(css);
            return buttongroup;
        },
        createButtongroupWrap:function (model) {
            var buttongroupWrap=COM.util.HTMLUtil.createELement('<div class="buttonGroupWrap adf_wrapper"></div>');
            return buttongroupWrap;
        },
        showFeedback:function (height,width) {
          var css={"position":"relative","overflow":"visible","border":"1px dashed #808080"};
          if(this.feedbackDom == null){
              var button=COM.util.HTMLUtil.createELement('<button type="button" class="btn"></button>');
              this.feedbackDom=button[0];
          }
          if(height>0&&width>0){
              css.height=height;
              css.width=width;
          }else{
              css.minHeight=30;
              css.minWidth=60;
          }
            COM.util.HTMLUtil.getJqueryDOM(this.feedbackDom).css(css);
            this.domElement.children[0].appendChild(this.feedbackDom);
            return COM.util.HTMLUtil.getBounds(this.feedbackDom);
        },
        eraseFeedback:function () {
            if(COM.util.HTMLUtil.hasChild(this.domElement, this.feedbackDom)) {
                this.domElement.children[0].removeChild(this.feedbackDom);
            }
        },
        layoutChild : function(child){
            var childDom = child.getDomElement();
            var layoutData = child.getLayoutData();
            if(layoutData){
                var css = {};
                if(layoutData.x >= 0) {
                    css.width = layoutData.x;
                }
                if(layoutData.y >= 0) {
                    css.height = layoutData.y;
                }
                $(childDom).css(css);
            }
        }
    });